package chapter3.six;

import chapter3.BiNode;

public class Test {

	
	private static BiNode pHead=null;
	private static BiNode pEnd=null;
	
	public static void inOrderBSTree(BiNode root) {
		if(null==root) {
			return;
		}
		
		inOrderBSTree(root.lChild);
		
		root.lChild=pEnd;
		
		if(null==pEnd) {
			pHead=root;
		}else {
			pEnd.rChild=root;
		}
		
		inOrderBSTree(root.rChild);
	}
	
	
	public static void main(String[] args) {
		int arr[]= {1,2,3,4,5,6,7};
		
		BiNode root;
		
		root=chapter3.two.Test.arraytotree(arr,0,arr.length-1);
		
		inOrderBSTree(root);
		
		BiNode cur;
		
		System.out.println("转换后双向链表正向遍历：");
		
		for(cur=pHead;cur!=null;cur=cur.rChild) {
			System.out.println(cur.data+" ");
		}
		
		System.out.println();
		
		System.out.println("转换后双向链表逆向遍历：");
		
		for(cur=pEnd;cur!=null;cur=cur.lChild) {
			System.out.println(cur.data+" ");
		}
	}
}
